import { Form, Table, Spin, Row, Col, message } from 'antd';
import Cls from 'classnames';
import { useContext, useEffect, useMemo, useState, useRef, Ref } from 'react';
import { connect } from 'umi';
import { getTableColumn } from '../mconfig/TransferTablecolumn';
import { IAllotActionEnum, TransferManageContext, useAllotManageReducer } from '../mconfig';

const TransferView: React.FC<any> = ({ pageType, openMaterialModalStatus, mapLoading, loadMapInfo }) => {
  const { materielList, curRes, allotDispatch } = useContext(TransferManageContext);

  const [isModalOpen, setIsModalOpen] = useState(false);
  const [checkMaterialList, setCheckMaterialList] = useState<Record<string, any>[]>([]);

  const delSelectRow = (record: any) => {
    const tempArr = [...materielList];
    const newData = tempArr?.filter((item: any) => item.id != record.id);

    setCheckMaterialList(newData);
    allotDispatch({
      type: IAllotActionEnum.SELECT_MATERIEL,
      payload: newData,
    });
  };

  const getTable: any = useMemo(() => {
    return getTableColumn(pageType, delSelectRow, openMaterialModalStatus, mapLoading, loadMapInfo);
  }, [materielList]);

  return (
    <>
      <div className={Cls('list-table', 'descriptionsType-tableSty')} style={{ marginTop: '10px' }}>
        <Table columns={getTable} bordered size="small" dataSource={materielList} scroll={{ x: 1200, y: '' }} pagination={false} rowKey={(res) => res?.id} />
      </div>
    </>
  );
};

export default connect(({ baseLogin, navTab }: Record<string, any>) => ({
  curRes: baseLogin?.permissions,
  navTab,
}))(TransferView);
